package com.learn.actionplatfo.controller;

import com.learn.actionplatfo.bean.GoodForUser;
import com.learn.actionplatfo.bean.Price;
import com.learn.actionplatfo.bean.User;
import com.learn.actionplatfo.service.GoodForUserService;
import com.learn.actionplatfo.service.GoodService;
import com.learn.actionplatfo.service.PriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PriceController {

    @Autowired
    GoodForUserService goodForUserService;

    @Autowired
    GoodService goodService;

    @Autowired
    PriceService priceService;


    @RequestMapping("/priceUpdate")
    public String updatePriceById(String id, User user, Model model){
        GoodForUser gfuById = goodForUserService.getGFUById(Integer.parseInt(id));
        model.addAttribute("gfu",gfuById);
        model.addAttribute("user",user);
/*        System.out.println(id);
        System.out.println(user.toString());*/
        return "bidding";
    }

    @RequestMapping("/biddingPrice")
    public String biddingPrice(User user,double newPrice,int goodId,int userId){
        Price price = priceService.getPriceByGoodId(goodId);
        price.setPriceNow(newPrice);
        price.setPriceBuyUserNo(userId);
        priceService.updatePrice(price);

        return "redirect:/main.html";
    }
}
